package com.jinjia.ordersys;

import com.jinjia.ordersys.service.PrintTokenService;
import com.jinjia.ordersys.util.ConstantUtil;
import com.jinjia.ordersys.util.IpUtil;
import com.jinjia.ordersys.yilianyun.Methods;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.StringUtils;

/**
 * @Description: 项目启动类
 * @Author: fenghouzhi
 * @Date: 2018/10/9
 * @Time: 10:40 AM
 */
@Slf4j
@MapperScan("com.jinjia.ordersys.dao")
@SpringBootApplication
public class OrdersysApplication {

    @Resource
    PrintTokenService printTokenService;

    public static void main(String[] args) {
        SpringApplication.run(OrdersysApplication.class, args);
        generateToken();
        log.info("项目启动完成!\t本机IP地址:  " + IpUtil.getLocalIP());
    }

    private static void generateToken() {
        try {
            Methods.getInstance().init(ConstantUtil.CLIENT_ID, ConstantUtil.CLIENT_SECRET);
            String yilianyunToken = Methods.getInstance().getFreedomToken();
            if (!StringUtils.isEmpty(yilianyunToken)) {
                ConstantUtil.ACCESS_TOKEN = yilianyunToken;
                log.info("access_token info:  {}", ConstantUtil.ACCESS_TOKEN);
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("打印服务初始化异常");
        }
    }

}